﻿//-----------------------------------------------------------------------
// <copyright file="MainWindowReadSettingsCommand.cs" company="AFS">
// Copyright (c) AFS. All rights reserved.
//
//    This file is part of Chatbox.
//
//    Chatbox is free software: you can redistribute it and/or modify
//    it under the terms of the GNU Lesser General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    any later version.
//
//    Chatbox is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//    GNU Lesser General Public License for more details.
//
//    You should have received a copy of the GNU Lesser General Public License
//    along with Chatbox. If not, see http://www.gnu.org/copyleft/lesser.html
// </copyright>
//----------------------------------------------------------------------- 
namespace ChatBox.UI.Windows.Main
{
    using ChatBox.DomainObjects.Settings;
    using ChatBox.Interfaces;
    using ChatBox.UI.Commands;
    using ChatBox.UI.ViewModels;
    using ChatBox.XamlUtility;

    /// <summary>
    /// Command to read settings ont main window view model
    /// </summary>
    public class MainWindowReadSettingsCommand : GenericCommandBase<MainWindowViewModel>
    {
        /// <summary>
        /// The source of UI settings
        /// </summary>
        private readonly IUISettingsRepository uiSettingsRepository;

        /// <summary>
        /// Initializes a new instance of the MainWindowReadSettingsCommand class
        /// </summary>
        /// <param name="uiSettingsRepository">the source of Ui settings</param>
        public MainWindowReadSettingsCommand(IUISettingsRepository uiSettingsRepository)
        {
            this.uiSettingsRepository = uiSettingsRepository;
        }

        /// <summary>
        /// Execute the read settings command
        /// </summary>
        /// <param name="value">the command data</param>
        public override void ExecuteOnValue(MainWindowViewModel value)
        {
            UISettingsData uiSettings = this.uiSettingsRepository.ReadSettings();

            value.Speak.SpeakVisibilityState = uiSettings.ShowSpeak.ToVisibilityAnimationState();
            value.Speak.SpeakVisibility = uiSettings.ShowSpeak.ToVisibility();

            value.TopicVisibilityState = uiSettings.ShowTopic.ToVisibilityAnimationState();
            value.TopicVisibility = uiSettings.ShowTopic.ToVisibility();

            value.ThrobberVisibilityState = uiSettings.ShowThrobber.ToVisibilityAnimationState();
            value.ThrobberVisibility = uiSettings.ShowThrobber.ToVisibility();

            value.OtherUsersVisibilityState = uiSettings.ShowOtherUsers.ToVisibilityAnimationState();
            value.OtherUsersVisibility = uiSettings.ShowOtherUsers.ToVisibility();

            value.TooltipFontSize = uiSettings.TooltipFontSize;

            value.Speak.UseBuiltInSpellchecker = uiSettings.UseBuiltInSpellchecker;

            if (value.PublicMessageFormatOptions != null)
            {
                value.PublicMessageFormatOptions.FontSize = uiSettings.PublicMessageFontSize;
                value.PublicMessageFormatOptions.ShowSendPrivateMessageButton =
                        uiSettings.ShowSendPrivateMessageButtonInPublicChat;
            }

            if (value.TopicFormatOptions != null)
            {
                value.TopicFormatOptions.FontSize = uiSettings.TopicFontSize;
            }

            value.Speak.SpeakFontSize = uiSettings.SpeakFontSize;
            value.TooltipFontSize = uiSettings.SpeakFontSize;
        }
    }
}
